import request from './request'

const key = 'fb46be605b812f8c84d85c8b04aaed39'

// 通过ip地址查询所在城市
// get  /v3/ip?key=...
export const getCityByIp = () => {
  return request({
    url: '/v3/ip',
    method: 'get',
    params: {
      key: key,
    },
  })
}

// 通过城市名查询adcode
// get  /v3/config/district?keywords=城市名&key=...
export const getAdcodeByCity = (city) => {
  return request({
    url: '/v3/config/district',
    method: 'get',
    params: {
      keywords: city,
      key: key,
    },
  })
}

// 通过adcode查询城市实况天气
// get  /v3/weather/weatherInfo?city=adcode&key=...
export const getLivesWeatherByAdcode = (adcode) => {
  return request({
    url: '/v3/weather/weatherInfo',
    method: 'get',
    params: {
      city: adcode,
      key: key,
    },
  })
}

// 通过adcode查询城市预报天气
// get  /v3/weather/weatherInfo?city=adcode&key=...&extensions=all
export const getForecastWeatherByAdcode = (adcode) => {
  return request({
    url: '/v3/weather/weatherInfo',
    method: 'get',
    params: {
      city: adcode,
      key: key,
      extensions: 'all',
    },
  })
}
